package com.example.scoket;

import com.example.config.SerialComm4MainWindows;
import com.example.config.WebSocketServer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.io.IOException;
import java.util.Random;


@SpringBootApplication(scanBasePackages="com.example")
public class ScoketApplication {

    public static void main(String[] args) {
        SpringApplication.run(ScoketApplication.class, args);
//        try {
//            //"/dev/ttyS0"
//            (new SerialComm4MainWindows()).connect("com1");
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
        try
        {
            while (true)
            {
                Thread.sleep(500L);
//                String ran1 = getRandom(4);
                String ran1 = "1234";
                WebSocketServer.sendInfo("0" + ran1 + "0", null);
                WebSocketServer.sendInfo("0" + ran1 + "0", null);
//                ran1 = getRandom(4);
                WebSocketServer.sendInfo("0" + ran1 + "0", null);
                WebSocketServer.sendInfo("0" + ran1 + "0", null);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public static String getRandom(int length)
    {
        String val = "";
        Random random = new Random();
        for (int i = 0; i < length; i++) {
            val = val + String.valueOf(random.nextInt(10));
        }
        return val;
    }
}
